home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cpptutor.arc / OVERLOAD.CPP < prev    next >
Text File  |  1991-04-28  |  1KB  |  48 lines

  1.                                      // Chapter 4 - Program 6
  2. #include "iostream.h"
  3.  
  4. overload do_stuff;
  5. int do_stuff(const int);       // This squares an integer
  6. int do_stuff(float);           // This triples a float & returns int
  7. float do_stuff(const float, float); // This averages two floats
  8.  
  9. main()
  10. {
  11. int index = 12;
  12. float length = 14.33;
  13. float height = 34.33;
  14.  
  15.    cout << "12 squared is "    << do_stuff(index)         << "\n";
  16.    cout << "24 squared is "    << do_stuff(2 * index)     << "\n";
  17.    cout << "Three lengths is " << do_stuff(length)        << "\n";
  18.    cout << "Three heights is " << do_stuff(height)        << "\n";
  19.    cout << "The average is "   << do_stuff(length,height) << "\n";
  20. }
  21.  
  22. int do_stuff(const int in_value)      // This squares an integer
  23. {
  24.    return in_value * in_value;
  25. }
  26.  
  27. int do_stuff(float in_value)    // Triples a float & return int
  28. {
  29.    return (int)(3.0 * in_value);
  30. }
  31.  
  32.                                       // This averages two floats
  33. float do_stuff(const float in1, float in2)
  34. {
  35.    return (in1 + in2)/2.0;
  36. }
  37.  
  38.  
  39.  
  40.  
  41. // Result of execution
  42. //
  43. // 12 squared is 144
  44. // 24 squared is 576
  45. // Three lengths is 42
  46. // Three heights is 102
  47. // The average is 24.330002
  48.